package com.example.deliveryapplication

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.deliveryapplication.entity.SelectString

class CenterStringListAdapter(private val context: Context, private val mList: List<SelectString>, private val listener: CallBack?) : BaseRecyclerViewAdapter(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_center_string_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mTextView.text=data.name
            if(data.select){
                holder.mTextView.setTextColor(Color.parseColor("#03A5FD"))
            }else{
                holder.mTextView.setTextColor(Color.parseColor("#000000"))
            }
            holder.mParentLL.setOnClickListener {
                listener?.onItemClick(position,data)
            }
            holder.deleteTV.setOnClickListener {
                listener?.onItemDelete(position,data)
            }
            holder.editTV.setOnClickListener {
                listener?.onItemEdit(position,data)
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mTextView: TextView = view.findViewById(R.id.mTextView)
        val mParentLL: LinearLayout = view.findViewById(R.id.mParentLL)
        val deleteTV:TextView=view.findViewById(R.id.deleteTV)
        val editTV:TextView=view.findViewById(R.id.editTV)
    }

    interface CallBack {
        fun onItemClick(position: Int,data:SelectString)
        fun onItemDelete(position: Int,data: SelectString)
        fun onItemEdit(position: Int,data: SelectString)
    }

}